(function (aopc) {
    aopc.addExpandPage(823, function (get) {
        const Common = get('UtilsCommon', 'Common');
        const Bridge = get('UtilsCommon', 'Bridge');

        return {
            expandInit() {
                this.container_view = this.getProperty('container_view');
                this.dialog_meeting_users = this.getProperty('dialog_meeting_users');
                this.user_views = this.getViewProperty(this.dialog_meeting_users, 'user_views');
                this.meeting_sign = this.getProperty('meeting_sign');
                this.left_menus = this.getProperty('left_menus');
                this.subjectsProperty = this.getProperty('Subjects');
                this.keywordProperty = this.getProperty('keyword');
                this.searchTypeProperty = this.getProperty('SearchType');
                this.searchTypeProperty.valueChange = this.searchTypeChange.bind(this);
                this.isMeetingIndex = true;
                this.center_view = this.getProperty('center_view');
                this.meeting_host = this.getProperty('meeting_host');
                this.meeting_share = this.getProperty('meeting_share');
                this.isHost = false;
                this.unite_views = {};

                Bridge.setReceiveFunction('downloadProgress', (data) => this.downloadProgress(data.Files));
                Bridge.setReceiveFunction('setShareText', (data) => this.setShareText(data.IsPublish, !!window.receSharingData));

                window.setEndReceShare = () => {
                    this.setShareText(false, !!window.receSharingData);
                }
            },
            setSubjectProperties({ data, view }) {
                const fileCount = this.getViewProperty(view, 'FileCount');
                fileCount.isExpand = !!data.IsExpand;
                if (fileCount.isExpand) {
                    const files = this.getViewProperty(view, 'Files');
                    files.isVisible = true;
                }
            },
            setInit() {
                this.isHost = !!this.getIsHost();
                this.meeting_host.isVisible = this.isHost;
            },
            setIsHost() {
                this.setIsVisible(this.meeting_host, this.isHost);
                for (let key in this.unite_views) {
                    this.setIsVisible(this.unite_views[key], this.isHost);
                }
            },
            showUsersDialog({ property }) {
                if (property.isLaoding) return;
                const { SubjectId, UserCount } = property.data;
                if (UserCount === 0) return;

                const { serviceName, actionName } = this.dialog_meeting_users.serviceInterface;
                const payload = { pathQuery: `&$filter=SubjectId eq @SubjectId&@SubjectId=${SubjectId}` }

                property.isLoading = true;
                this.dispatchAction(serviceName, actionName, payload).then(res => {
                    property.isLoading = false;
                    if (res.isSuccess !== false) {
                        const dataList = [];
                        let names = [];
                        res.forEach(r => {
                            names.push(r.Name);
                            if (names.length === 6) {
                                dataList.push({ names });
                                names = [];
                            }
                        });
                        if (names.length > 0) {
                            for (let i = names.length; i < 6; i++) {
                                names.push('');
                            }
                            dataList.push({ names });
                        }
                        this.user_views.dataList = dataList;
                        this.dialog_meeting_users.setIsVisible(true);
                    }
                });
            },
            setPropertyValue(p, v) {
                p.value = v;
                p.setValue && p.setValue(v);
            },
            setShareText(isPublish, isPlaying) {
                this.setPropertyValue(this.meeting_share.properties[1], isPublish ? '结束共享' : isPlaying ? '加入共享' : '共享屏幕');
                if (!this.isHost) {
                    this.setIsVisible(this.meeting_share, isPlaying);
                }
            },
            setMenusVisible({ property, view }) {
                if (property.isLoading) return;
                property.isExpand = !property.isExpand;
                let imgUrl;
                if (this.theme === 'red') imgUrl = property.isExpand ? 'images/yxinmt_h5/25081716170294612.png' : 'images/yxinmt_h5/25081716095884887.png';
                else imgUrl = property.isExpand ? 'images/yxinmt_h5/24120815163316233.png' : 'images/yxinmt_h5/24120811143325660.png';
                property.setValue(imgUrl);

                const left_menus = view.properties[1];
                const p2 = left_menus.properties[0];

                property.isLoading = true;
                if (property.isExpand) {
                    left_menus.setIsVisible(true);
                    p2.onLoad = () => {
                        p2.style.right = 0;
                        p2.refresh();
                    }
                    setTimeout(() => property.isLoading = false, 700);
                } else {
                    delete p2.style.right;
                    p2.refresh && p2.refresh();
                    setTimeout(() => { left_menus.setIsVisible(false); property.isLoading = false }, 700);
                }
            },
            setFileVisible({ property, view }) {
                if (!property.data.Files || property.data.Files.length === 0) {
                    property.disabled = true;
                    return;
                }
                const fileCountProperty = property.properties[1];
                fileCountProperty.setIsExpand();
                const files = view.properties[2];
                files.isVisible = !files.isVisible;
                files.setIsVisible(files.isVisible);
            },
            setFileRow({ data, view }) {
                const file_icon = this.getViewProperty(view, 'file_icon');
                if (file_icon) {
                    file_icon.imgUrl = this.getFileIcon(data);
                };
                const p = this.getViewProperty(view, 'DownloadProgress');
                if (p) {
                    p.spanId = "span_" + data.FileId;
                    if (data.Percentage === 100) {
                        p.spanStyle.color = '#2a2a2a';
                    }
                }
                const p2 = this.getViewProperty(view, 'unite_view');
                if (p2) {
                    p2.isVisible = this.isHost;
                    this.unite_views[data.FileId] = p2;
                }
            },
            getFileIcon(data) {
                const t = data.FileType.toLowerCase();
                const vt = '.mp4,.mov,.avi,.mkv,.rmvb';
                const it = '.jpg,.jpeg,.png,.gif,.svg';
                if (t === '.doc' || t === '.docx') return "/images/yxinmt_h5/25080313563175553.png";
                else if (t === '.xls' || t === '.xlsx') return "/images/yxinmt_h5/25080313565026910.png";
                else if (t === '.ppt' || t === '.pptx') return "/images/yxinmt_h5/25080313564674186.png";
                else if (t === '.pdf') return "/images/yxinmt_h5/25080313563543435.png";
                else if (vt.indexOf(t) >= 0) return '/images/yxinmt_h5/25080521052203829.png';
                else if (it.indexOf(t) >= 0) return '/images/yxinmt_h5/25080521052598726.png';
                else return "/images/yxinmt_h5/25080521052936371.png";
            },
            setSelfHide({ property, e }) {
                const ele = property.getElement();
                if (ele === e.target) property.setIsVisible(false);
            },
            expandGetMeetingData({ entityData }) {
                if (this.pageData.isStart === 'true') entityData.queryString = "IsStart=true";
                return entityData;
            },
            expandGetMeetingSubjectData({ entityData }) {
                entityData.queryString = "IsList=true";
                return entityData;
            },
            expandDataLoad({ data }) {
                this.entityData = data;
                const { Title } = data;
                this.isHost = data.DeviceRole === '主席';
                if (!data.IsInSign) {
                    this.setIsVisible(this.meeting_sign, false);
                    this.left_menus.style.width = this.isHost ? '1230rem' : '1080rem';
                    this.left_menus.refresh();
                }
                else if (!this.isHost) {
                    this.left_menus.style.width = '1230rem';
                    this.left_menus.refresh();
                }

                Bridge.jsToNative("getShareText");
                this.setIsVisible(this.meeting_share, this.isHost || !!window.receSharingData);
                this.setIsHost();

                if (this.isHost) {
                    this.webSocket.send('setCacheVideos', { Title, MeetingId: this.pageData.MeetingId });
                }
            },
            toMeetingShare() {
                const { MeetingId } = this.pageData;
                Bridge.jsToNative('toMeetingShare', { MeetingId });
            },
            reload(pageData) {
                this.pageData = pageData;
                this.container_view.reLoad();
                this.center_view.reLoad();
            },
            updateDeviceRole(isPresident) {
                this.isHost = !!isPresident;
                this.setIsHost();
            },
            expandSubjectDataLoad({ data }) {
                const { Subjects } = data;
                if (Subjects) {
                    const files = [];
                    this.fileObject = {};
                    Subjects.forEach(s => {
                        if (s.Files) {
                            s.Files.forEach(f => {
                                files.push(f);
                                this.fileObject[f.FileId] = f;
                            });
                        }
                    });
                    if (files.length > 0) Bridge.jsToNative('downloadFiles', { Files: files, MeetingId: this.pageData.MeetingId });
                }
            },
            setIsVisible(p, v) {
                p.isVisible = v;
                p.setIsVisible && p.setIsVisible(v);
            },
            searchData() {
                if (!this.subjectsProperty.dataSource2) this.subjectsProperty.dataSource2 = Common.clone(this.subjectsProperty.value);
                if (!this.subjectsProperty.dataSource2) return;

                const dataSource = Common.clone(this.subjectsProperty.dataSource2);
                const dataList = [];
                dataSource.forEach(d => {
                    if (d.Files) d.Files.forEach(f => {
                        dataList.push({ File: { ...f }, Subject: d });
                    })
                    else dataList.push({ File: { FileName: '' }, Subject: d })
                });

                const keyword = this.keywordProperty.getValue().toLowerCase();
                const searchType = parseInt(this.searchTypeProperty.getValue());

                const dataList2 = [];
                dataList.forEach(d => {
                    const f = d.File;
                    const s = d.Subject;
                    s.Files = [];
                    let blExists = false;
                    if (!Common.isNullOrEmpty(keyword)) {
                        if (s.Name.toLowerCase().indexOf(keyword) >= 0 || f.FileName.toLowerCase().indexOf(keyword) >= 0) blExists = true;
                    } else blExists = true;

                    if (blExists && searchType > 0) {
                        blExists = false;
                        const t = searchType === 1 ? 'pdf' : searchType === 2 ? 'doc' : searchType === 3 ? 'xls' : 'ppt';
                        if (f.FileType.indexOf(t) >= 0) blExists = true;
                    }
                    if (blExists) dataList2.push(d);
                });

                const obj = {};
                dataList2.forEach(d => {
                    const f = d.File;
                    f.Id = Common.createGuid();
                    d.Subject.Files.push(f);
                    if (!obj[d.Subject.SubjectId]) {
                        obj[d.Subject.SubjectId] = d.Subject;
                    }
                });

                const list = [];

                for (const key in obj) {
                    const s = obj[key];
                    s.SubjectId = Common.createGuid();
                    s.IsExpand = true;
                    s.FileCount = s.Files.length + '项文件';
                    list.push(s);
                }

                this.subjectsProperty.setValue(list);
            },
            searchTypeChange(value, selectData, property) {
                if (!property.isChanged) return;
                this.searchData();
            },
            openFile({ property }) {
                const { MeetingId } = this.pageData;
                property.data.MeetingId = MeetingId;
                property.data.IsHost = this.isHost;

                Bridge.openFile(property.data);
            },
            lockScreen() {
                Bridge.jsToNative("lockScreen", { MeetingId: this.pageData.MeetingId });
            },
            toWhiteboard() {
                const { MeetingId } = this.pageData;
                Bridge.jsToNative("toWhiteboard", { MeetingId });
            },
            toMeetingRecord() {
                const { MeetingId } = this.pageData;
                Bridge.jsToNative("toMeetingRecord", { MeetingId });
            },
            openVideoPlay() {
                const { MeetingId } = this.pageData;
                Bridge.jsToNative("openVideoPlay", { MeetingId, IsHost: this.isHost });
            },
            uniteOpen({ property }) {
                const { MeetingId } = this.pageData;
                property.data.MeetingId = MeetingId;
                property.data.IsHost = this.isHost;

                this.webSocket.send('uniteOpen', property.data);
                Bridge.openFile(property.data);
            },
            uniteClose({ property }) {
                const { MeetingId } = this.pageData;
                property.data.MeetingId = MeetingId;

                this.webSocket.send('uniteClose', property.data);
                this.alertSuccess('统一关闭的指令已发出');
            },
            downloadProgress(files) {
                for (let i = 0; i < files.length; i++) {
                    const file = files[i];
                    const ele = document.getElementById("span_" + file.FileId);
                    if (ele) {
                        ele.innerHTML = file.DownloadProgress || '';
                        if (file.Percentage === 100) {
                            ele.style.color = '#2a2a2a';
                        }
                    }
                    else {
                        const file2 = this.fileObject[file.FileId];
                        if (file2) {
                            file2.DownloadProgress = file.DownloadProgress;
                            file2.Percentage = file.Percentage;
                        }
                    }
                }
            }
        }
    });
})(window.aopc);